
var rect;
var captureCallback;
var url;
var currentTabId;

chrome.tabs.onActivated.addListener(function(activeInfo) {
    currentTabId = activeInfo.tabId;
});

function showprog(frame)
{
	//console.log("progress is "+prog);
	chrome.tabs.sendMessage(currentTabId,{cmd:"refresh_progress",prog:frame},function(response){
		console.log(response);
	});
}

//chrome.tabs.sendMessage(null,{cmd:"refresh_progress",prog:20});

var startHandler = function(e){
	chrome.contextMenus.removeAll(function(){
		console.log("menu removed");
	});

	console.log("capture("+rect[0]+","+rect[1]+","+rect[2]+","+rect[3]);
	

	console.log("url="+url);
	document.getElementById("pluginobj").start_capture(url,rect[0],rect[1],rect[2],rect[3]);
	captureCallback();
};

function endHandler(){
	document.getElementById("pluginobj").stop_capture();
};
		
 chrome.extension.onMessage.addListener(function(request,sender,sendResponse) {
	 /*console.log("msg is"+request.message);
	 console.log("sender is"+request.sender);
	 console.log("resp is"+request.sendResponse);*/

	if(request.cmd == "status"){
		var state = document.getElementById("pluginobj").is_recording();
		sendResponse(state);
	}else  if(request.cmd == "capture") {
		rect = request.rect;
		url = request.url;
		console.log("url1="+url);
		document.getElementById("pluginobj").start_capture(url,rect[0],rect[1],rect[2],rect[3])

		captureCallback=sendResponse;
		captureCallback();
	    return true;
    }else if(request.cmd == "stop_capture"){
		document.getElementById("pluginobj").stop_capture();
	};
});